<?php

namespace App\Http\Controllers\Web;

use App\Repositories\TalentRelationshipRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class TalentRelationshipController extends Controller
{
    //
    private $talentRelationShip;

    public function __construct( TalentRelationshipRepository $talentRelationshipRepository)
    {
        $this->middleware('auth');
        $this->talentRelationShip = $talentRelationshipRepository;
    }

    public function createOrUpdate(Request $request) {
//        dd($request->all());
        $ret = null;
        if(!$request->id) {
            $ret =  $this->talentRelationShip->create($request->all());
        } else {
            $relationship = $this->talentRelationShip->find($request->id);
            $ret =  $this->talentRelationShip->update($relationship, $request->all());
        }
        return response()->json([
            'errors' =>  false,
            'data' => $ret
        ]);
    }

    public function destroy(Request $request) {
        $relation = $this->talentRelationShip->find($request->id);
        $ret = $this->talentRelationShip->destroy($relation);

        return response()->json([
            'errors' =>  false,
            'data' => $ret
        ]);
    }
}
